﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OmniKits
{
    using Extensions;
    using NullGuard;

    public interface IHasTask<out TTask>
        where TTask : Task
    {
        TTask CurrentTask { get; }
    }

    [NullGuard(ValidationFlags.None)]
    public static class HasTaskExtensions
    {
        //public static bool IsNotRunning<T>(this T source)
        //    where T : IHasTask<Task>
        //{
        //    return source == null || source.Task.IsNotRunning();
        //}
        //public static bool IsRunning<T>(this T source)
        //    where T : IHasTask<Task>
        //{
        //    return !source.IsNotRunning();
        //}

        public static bool IsTaskNotRunning<TTask>(this IHasTask<TTask> source)
            where TTask : Task
        {
            return source == null || source.CurrentTask.IsNotRunning();
        }
        public static bool IsTaskRunning<TTask>(this IHasTask<TTask> source)
            where TTask : Task
        {
            return !source.IsTaskNotRunning();
        }
    }
}
